//
//  NetWorkManager.h
//  xiaoyixiu
//
//  Created by hanzhanbing on 16/6/14.
//  Copyright © 2016年 柯南. All rights reserved.
//

#import <AFNetworking/AFNetworking.h>
/**
 *  宏定义请求成功的block
 *
 *  @param responseObject 请求成功返回的数据
 */
typedef void(^XJYResponseSuccess)(NSURLSessionDataTask *task, id responseObject);

/**
 *  宏定义请求失败的block
 *
 *  @param error 报错信息
 */
//宏定义成功block 回调成功后得到的信息
typedef void (^HttpSuccess)(id data);
//宏定义失败block 回调失败信息
typedef void (^HttpFailure)(NSError *error);
typedef void(^XJYResponseFail)(NSURLSessionDataTask *task, NSError *error);

/**
 *  上传或者下载的进度
 *
 *  @param progress 进度
 */
typedef void(^XJYProgress)(NSProgress *progress);
@interface NetWorkManager : AFHTTPSessionManager

+ (instancetype)sharedManager;
#pragma mark - 接口请求(返回Data数据流)

/**
 *  无弹框POST请求(只请求data数据流，具体操作放在使用的地方)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
-(void)getWithUrlString:(NSString *)urlString parameters:(NSDictionary *)parameters success:(HttpSuccess)success failure:(HttpFailure)failure;
 
 
//post请求
-(void)postWithUrlString:(NSString *)urlString parameters:(NSDictionary *)parameters success:(HttpSuccess)success failure:(HttpFailure)failure;

- (NSURLSessionDataTask *)postData:(NSString *)name
                        parameters:(NSDictionary *)parameters
                           success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                           failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 *  无弹框GET请求(只请求data数据流，具体操作放在使用的地方)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
- (NSURLSessionDataTask *)getData:(NSString *)name
                       parameters:(NSDictionary *)parameters
                          success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                          failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

#pragma mark - 接口请求(返回JSON数据)

/**
 *  POST请求(弹框)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
- (NSURLSessionDataTask *)postJSON:(NSString *)name
                        parameters:(NSDictionary *)parameters
                           success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                           failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 *  GET请求(弹框)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
- (NSURLSessionDataTask *)getJSON:(NSString *)name
                       parameters:(NSDictionary *)parameters
                          success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                          failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 *  POST请求(无弹框)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
- (NSURLSessionDataTask *)postNoTipJSON:(NSString *)name
                        parameters:(NSDictionary *)parameters
                           success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                           failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
 *  GET请求(无弹框)
 *
 *  @param name       接口名称
 *  @param parameters 传参
 *  @param success    成功回调
 *  @param failure    失败回调
 *
 *  @return NSURLSessionDataTask
 */
- (NSURLSessionDataTask *)getNoTipJSON:(NSString *)name
                       parameters:(NSDictionary *)parameters
                          success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                          failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;


#pragma mark 文件上传
- (NSURLSessionDataTask *)postfile:(NSString *)name
                        parameters:(NSDictionary *)parameters
         constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block

                           success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                           failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;



-(NSURLSessionDataTask *)deleteFile:(NSString *)name paramters:(NSDictionary *)parameters
                            success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                            failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;

/**
*  下载文件
*
*  @param url      请求网络路径
*  @param fileURL  保存文件url
*  @param progress 下载进度
*  @param success  成功回调
*  @param fail     失败回调
*
*  @return 返回NSURLSessionDownloadTask实例，可用于暂停继续，暂停调用suspend方法，重新开启下载调用resume方法
*/
- (void)geNewJSON:(NSString *)name
parameters:(NSDictionary *)parameters
   success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
   failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
- (void)postJsonWithURLString:(NSString *)urlString parameters:(NSDictionary *)parameters success:(void (^)(id responseObject))success failure:(void (^)(NSError *error))failure;
@end

